package com.cqyc.shop.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cqyc.shop.comm.Pager;
import com.cqyc.shop.comm.commException;
import com.cqyc.shop.domain.Shop;
import com.cqyc.shop.services.ShopServices;

@WebServlet(urlPatterns="/crazyTime.do")
public class crazyTimeServlet extends HttpServlet{
	private static final long serialVersionUID = -5408861166743368956L;
	private Logger logger = LoggerFactory.getLogger(getClass());
	private ShopServices shopServices = new ShopServices();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("疯狂时间开始");
		try {
			Shop shop = new Shop();
					logger.debug("shop创建执行");
			//特价秒杀区
			Pager pager_tjms = new Pager();
			pager_tjms.setPageSize(4);
			pager_tjms.setCurrentPage(1);
			shop.setShopname("水果");
			
			
			List<Shop> shops_tjms = shopServices.findPager(shop,pager_tjms);

			request.setAttribute("shops_tjms",shops_tjms);

			
			//爆款热卖区
			Pager pager_bkrm = new Pager();
			pager_bkrm.setPageSize(4);
			pager_bkrm.setCurrentPage(1);
			shop.setShopname("肉类");
			
			
			List<Shop> shops_bkrm = shopServices.findPager(shop,pager_bkrm);

			request.setAttribute("shops_bkrm",shops_bkrm);
			
			
			//限时抢购区
			Pager pager_xsqg = new Pager();
			pager_xsqg.setPageSize(16);
			pager_xsqg.setCurrentPage(1);
			shop.setShopname("水产");
			
			
			List<Shop> shops_xsqg = shopServices.findPager(shop,pager_xsqg);

			request.setAttribute("shops_xsqg",shops_xsqg);
			
			logger.debug("查询数据成功");
			request.getRequestDispatcher("/crazyTime.jsp").forward(request, response);
		} catch (Exception e) {
			request.getRequestDispatcher("/crazyTime.jsp").forward(request, response);
			throw new commException("list查找出现异常");
		}
	}
	
	

}
